/**
 * 案件关联页面,选择仲裁员
 */

const userList = require('../../config')
const Login = require('../../login/index')
const ajax = require('../../../tool/ajax')
let page, config;

/**
 * 开始
 */

const start = async (pupConfig, caseInfo) => {
  page = pupConfig.page;
  config = pupConfig.config.common;

  await Login(pupConfig, userList.filing.respondent1.id);
  await openCaseAssociation();
  await inputCode(pupConfig, caseInfo);
}

/**
 * 打开案件关联页
 */
const openCaseAssociation = async () => {
  await page.goto(config.host + 'tribunal/caseAssociation');
}


/**
 * 案件关联
 */
const inputCode = async (pupConfig, caseInfo) => {
  //等待页面加载完成
  await page.waitFor('.caseIdcode');
  //输入案件识别码
  await page.type('.caseIdcode>input', caseInfo.affinityCode);
  //截屏
  await screen(page,);
  //点击下一步
  await page.click('.association-caseIdcode-next>button');

  await ajax.waitForResponse(pupConfig.page, 'getAllCaseInfo.do');
  await page.goto(config.host + 'tribunal/caseAssociation');

}


/**
 * 截屏
 */
const screen = async (name = '案件关联') => {
  await page.screenshot({path: config.imgPath + 'tribunal/' + name + '.png'});
}


module.exports = start;
